#include "clockmenu.h"
#include "ui_clockmenu.h"
#include "all_drive.h"

extern all_drive a_drive;

clockmenu* lock=NULL;

clockmenu::clockmenu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::clockmenu)
{
    ui->setupUi(this);
    Timer_init();
    a_drive.startinit();
    lock=this;
    qDebug()<<"start!"<<endl;
}

void clockmenu::Timer_init()
{
    realtimeclock.setInterval(1000);
    realtimeclock.setInterval(1000);
    QTime currenttime = QTime::currentTime();
    QString currentTimeString = currenttime.toString("hh:mm:ss");
    ui->timelabel->setText(currentTimeString);
    QDate currentDate = QDate::currentDate();
    QString currentDateString = currentDate.toString("yyyy-MM-dd");
    ui->datelabel->setText(currentDateString);
    QDateTime currentWeek= QDateTime::currentDateTime();
    QString currentWeekString = currentWeek.toString("dddd");
    ui->weeklabel->setText(currentWeekString);
    connect(&realtimeclock,&QTimer::timeout,[&](){
        QTime currenttime = QTime::currentTime();
        QString currentTimeString = currenttime.toString("hh:mm:ss");
        ui->timelabel->setText(currentTimeString);
        QDate currentDate = QDate::currentDate();
        QString currentDateString = currentDate.toString("yyyy-MM-dd");
        ui->datelabel->setText(currentDateString);
        QDateTime currentWeek= QDateTime::currentDateTime();
        QString currentWeekString = currentWeek.toString("dddd");
        ui->weeklabel->setText(currentWeekString);
    });
    realtimeclock.start();
}

clockmenu::~clockmenu()
{
    delete ui;
}

void clockmenu::paintEvent(QPaintEvent *)
{
    QPainter p;
    p.begin(this);
    p.drawPixmap(0,0,width(),height(),QPixmap(":/images/Sitting on an Elk.png"));
}

bool clockmenu::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::MouseButtonPress)
    {
        // 切换到下一个界面
        NextPage();
        return true; // 停止事件传递
    }

    return clockmenu::eventFilter(obj, event);
}

void clockmenu::NextPage()
{
    // 创建下一个界面
    Widget * Login=new Widget();
    Login->setWindowState(Qt::WindowNoState);
    Login->setGeometry(this->geometry());
    Login->setWindowTitle("Administrator");
    Login->show();
    this->hide();
}

void clockmenu::on_pushButton_2_clicked()
{
    qDebug()<<"press"<<endl;
    NextPage();
}
